package daily.core

import daily.securety.Account

class Activity {

    Date start

    Date end

    String title

    String content

    String timeZone

    Account account

    static belongsTo = [account : Account]

    boolean allDay = true

    static mapping = {
        table('activities')
        account column: "account_id"
    }

    static constraints = {
        title blank: false
        content blank: false
        start nullable: false
        end nullable: false
        account nullable: false
    }

    String getPrettyTime(){
        def formatter = "yyyy-MM-dd HH:mm:ss";

        //全天
        if(allDay){
            formatter = 'yyyy-MM-dd'
        }

        if (start.compareTo(end) == 0) {
            return  start.format(formatter)
        }

        return "${start.format(formatter)} 至 ${end.format(formatter)}"

    }
}
